﻿namespace DesignModeConsole.结构型.装饰器模式;

/// <summary>
/// 装饰器服务
/// </summary>
public class DecoratorService : IService
{
    public void Main()
    {
        //日志记录的示例
        Log log = new DataBaseLog();

        LogWrapper lew1 = new LogErrorWrapper(log);
        //扩展记录错误严重类别
        lew1.Write("log message");

        Console.WriteLine("-----");

        LogWrapper lpw1 = new LogPriorityWrapper(log);
        //扩展记录优先级别
        lpw1.Write("log message");

        Console.WriteLine("----");

        LogWrapper lew2 = new LogErrorWrapper(log);
        LogWrapper logPriority = new LogPriorityWrapper(lew2);
        //同时扩展了错误严重级别和优先级别
        logPriority.Write("log message");

        //人穿衣服的示例  模拟人穿衣服的方案作为演示的例子
        var xc = new Persion("张三");
        Console.WriteLine("第一种装扮");

        var bigTrouser = new BigTrouser();
        var shirts = new TShirts();
        bigTrouser.Decorate(xc);
        shirts.Decorate(bigTrouser);
        shirts.Show();
    }
}

/// <summary>
/// 记录日志抽象类
/// </summary>
public abstract class Log
{
    public abstract void Write(string log);
}

public class DataBaseLog : Log
{
    public override void Write(string log)
    {
        Console.WriteLine("记录日志到数据库");
    }
}

public class TextFileLog : Log
{
    public override void Write(string log)
    {
        Console.WriteLine("记录日志到文本文件");
    }
}

public interface IError
{
    void SetError();
}

public interface IPriority
{
    void SetPriority();
}

public class DBErrorLog : DataBaseLog, IError
{
    public override void Write(string log)
    {
        SetError();
        base.Write(log);
    }

    public void SetError()
    {
        // 记录错误严重级别
    }
}

public class DbPriorityLog : DataBaseLog, IPriority
{
    public override void Write(string log)
    {
        SetPriority();
        base.Write(log);
    }

    public void SetPriority()
    {
        // 记录优先级别
    }
}

public class TextFileErrotLog : TextFileLog, IError
{
    public override void Write(string log)
    {
        SetError();
        base.Write(log);
    }

    public void SetError()
    {
        // 记录错误严重级别
    }
}

public class TextFilePriority : TextFileLog, IPriority
{
    public override void Write(string log)
    {
        SetPriority();
        base.Write(log);
    }

    public void SetPriority()
    {
        // 记录优先级别
    }
}

//实现接口的多重继承
public class DBEPLog : DataBaseLog, IError, IPriority
{
    public override void Write(string log)
    {
        SetError();
        SetPriority();
        base.Write(log);
    }

    public void SetError()
    {
        throw new NotImplementedException();
    }

    public void SetPriority()
    {
        throw new NotImplementedException();
    }
}

public class EFEPLog : TextFileLog, IError, IPriority
{
    public override void Write(string log)
    {
        SetError();
        SetPriority();
        base.Write(log);
    }

    public void SetError()
    {
        throw new NotImplementedException();
    }

    public void SetPriority()
    {
        throw new NotImplementedException();
    }
}